package com.stand.hardcode.controller;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.stand.hardcode.entity.StandUser;
import com.stand.hardcode.manager.UserManager;
import com.stand.hardcode.util.ParamsVerifier;
import com.stand.hardcode.util.RequestAttributes;
import com.stand.hardcode.util.StringTools;

public class UpdateProfileServlet extends HttpServlet{

	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		//noting?
	}
	
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		
		if(UserManager.IsLoggedIn(req)){
		
			String description = req.getParameter("description");
			
			if(ParamsVerifier.ParamsNotNull(description)){
				StandUser u = (StandUser)req.getSession().getAttribute(RequestAttributes.CURRENT_USER);
				u.setDescription(StringTools.escapeHTML(description));
				UserManager.UpdateUser(u);
				
				resp.sendRedirect("/profile");
			}
		
		}
	}
}
